﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using static UnityEngine.UI.Dropdown;

public class SelectMusicView : MonoBehaviour
{
    public Button back;
    public Dropdown selectMusic_dd;
    public Slider slider;
    public Text speedText;
    public Dropdown selectChar_dd;
    public Toggle showChinese;

    // Start is called before the first frame update
    void Start()
    {
        selectMusic_dd.options.Clear();
        for (int i = 0; i < Musices.all_music.Count; i++)
        {
            string optionText = Musices.all_music[i].name;
            if (i >= 8)
                optionText = "❤ " + optionText;
            OptionData option = new OptionData(optionText);
            selectMusic_dd.options.Add(option);
        }
        if (GameData.musicIndex >= selectMusic_dd.options.Count)
            GameData.musicIndex = 0;
        selectMusic_dd.value = GameData.musicIndex;
        slider.value = GameData.musicSpeed * 10;
        speedText.text = GameData.musicSpeed.ToString();
        selectChar_dd.value = GameData.selectChar;
        showChinese.isOn = GameData.isShowChinese;

        back.onClick.AddListener(() => 
        {
            this.gameObject.SetActive(false);
        });
        selectMusic_dd.onValueChanged.AddListener((value)=> 
        {
            GameData.musicIndex = value;
        });
        slider.onValueChanged.AddListener((value)=> {
            GameData.musicSpeed = value / 10;
            speedText.text = GameData.musicSpeed.ToString();
        });
        selectChar_dd.onValueChanged.AddListener((value)=> {
            GameData.selectChar = value;
            GameData.myChar = selectChar_dd.captionText.text;
        });
        showChinese.onValueChanged.AddListener((value)=> {
            GameData.isShowChinese = value;
        });
    }
}
